#import "Bill.h"
#import "BillsManager.h"

@interface Bill ()

@property NSMutableArray *orders;
@property NSMutableArray *orderIds;

@end

@implementation Bill

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.orders = [[NSMutableArray alloc] init];
        self.orderIds = [[NSMutableArray alloc] init];
    }
    return self;
}


- (void) setOrdersWithArray:(NSMutableArray*) array{
    if (array)
        self.orders = array;
}

-(void) addOrderId:(NSInteger) orderId{
    [self.orderIds addObject:[NSNumber numberWithInteger:orderId]];
}

- (Product*) orderAtIndex:(NSInteger) index{
    if (index > -1 && index < [self count]) {
        return self.orders[index];
    }
    else{
        return nil;
    }
}

- (NSInteger) orderIdAtIndex:(NSInteger) index{
    if (index > -1 && index < [self.orderIds count]) {
        return [self.orderIds[index] integerValue];
    }
    else
        return -1;
}

-(void) deleteOrderAtIndex:(NSInteger) index{
    if (index > -1 && index < [self count]){
        [self.orders removeObjectAtIndex:index];
        [BillsManager deleteOrder:[self orderIdAtIndex:index]];
    }
}

- (NSInteger) count{
    return [self.orders count];
}


@end
